package jp.co.cos.ittrick.channel.controller.admin.article;

import java.util.Date;

import jp.co.cos.ittrick.channel.model.ArticleModel;
import jp.co.cos.ittrick.channel.service.ArticleService;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;

public class ArticlePublicController extends Controller {

    private ArticleService articleService;

    public ArticlePublicController() {
        articleService = new ArticleService();
    }

    @Override
    public Navigation run() throws Exception {

        // リクエストパラメータ
        String article = asString("article");

        ArticleModel articleModel = articleService.getArticleByKey(Integer.valueOf(article));
        if(articleModel.getPublicFlg() != null && articleModel.getPublicFlg()) {
            articleModel.setPublicFlg(false);
        }else {
            articleModel.setPublicFlg(true);
            articleModel.setPublicDate(new Date());
        }

        articleService.update(articleModel);

        return redirect("/admin/article/");
    }
}
